package com.hongkou.tvstation.common.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.hongkou.tvstation.common.CodeCst;
import com.hongkou.tvstation.common.exception.GenericException;

public class GenericAction extends Action {
	public ActionForward process(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return null;
	}

	public MultiWarning processWarning(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return null;
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String continueFlag = request.getParameter(CodeCst.PARAM__CONTINUEFLAG);
		ActionForward actionForward = null;
		try {
			if (continueFlag == null) {
				MultiWarning multiWarning = processWarning(mapping, form,
						request, response);
				if (multiWarning != null && !multiWarning.isEmpty()) {
					request.setAttribute(CodeCst.ATTRIBUTE__MULTIWARNING,
							multiWarning);
					return mapping.getInputForward();
				}
			}
			if (form != null) {
				request.setAttribute(CodeCst.ATTRIBUTE__PARAMETER_MAP, request
						.getParameterMap());
			}
			actionForward = process(mapping, form, request, response);
		} catch (GenericException e) {
			actionForward = mapping
					.findForward(CodeCst.FORWARD__EXCEPTIONCONTROL);
		}
		return actionForward;
	}
}
